Ensure loggers receive Throwable objects to prevent crashes - #2067
Open
AciDCooL wants to merge 1 commit into
Open
Ensure loggers receive Throwable objects to prevent crashes#2067AciDCooL wants to merge 1 commit into
AciDCooL wants to merge 1 commit into
Conversation
…owable objects to prevent InvalidArgumentException crashes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical application crash that occurs whenever Organizr attempts to log an error message as a string rather than an Exception object.
The Problem
If a backend error occurs (for example, a database constraint or permission issue) and Organizr attempts to log it, the UI throws a Slim ApplicationError and completely halts:
(Or similarly for array_column() when it silently fails further down the stack due to the same logger issue).
This happens because the recently integrated Nekonomokochan\PhpJsonLogger\Logger package strictly requires its error() , critical() , alert() , and emergency() methods to receive a PHP \Throwable (Exception) object as the first parameter.
However, throughout the Organizr codebase, it is very common to pass simple text strings or arrays into the logger (e.g., $this-
The Fix
Instead of tracking down and modifying every single error() or critical() call across the entire codebase to pass an Exception, this PR updates the global logging wrappers in api/functions/log-functions.php .
The wrapper methods ( error , critical , alert , and emergency ) now proactively verify if the passed $msg is a \Throwable . If it is not, they safely wrap the string (or JSON-encoded array) into a new \Exception on the fly before passing it to the logger.
This bulletproofs the codebase, allowing developers to continue passing simple string messages to the logger without inadvertently triggering application-breaking crashes.